package cn.njyd.corejava.thread.myday05;

import java.util.concurrent.atomic.AtomicReference;

class User{
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public User() {
    }

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class AtomicReferenceDemo01 {
    public static void main(String[] args) {
        User user1 = new User("张三",20);
        AtomicReference<User> reference = new AtomicReference<>(user1);
        System.out.println(reference.get());
        User user2 = new User("李四",18);
        boolean b = reference.compareAndSet(user1,user2);
        System.out.println(b);
        System.out.println(reference.get());
    }
}


